#include<iostream>
#include<vector>
#include<queue>
#include"BST.h"
using namespace std;
  struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode() : val(0), left(nullptr), right(nullptr) {}
      TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
      TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  };
 
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root)
    {
        vector<vector<int>> vv;
        if (root == nullptr) return vv;
        q.push(root);
        int levelsize = q.size();
        while (levelsize ||!q.empty())
        {
            vector<int> v;
            while (levelsize--)
            {
                TreeNode* top = q.front();
                q.pop();
                v.push_back(top->val);
                if (top->left) q.push(top->left);
                if (top->right) q.push(top->right);
            }
            vv.push_back(v);
            levelsize = q.size();
        }
       // reverse ( vv.begin(), vv.end());
        return vv;
    }
private:
    queue<TreeNode*> q;
};

//int main()
//{
//    vector<int> arr = { 3,9,20,15,7 };
//    tom::BSTree<int>bs;
//    for (auto it : arr)
//    {
//        bs.insert(it);
//    }
//    bs.InOrder();
//
//    Solution s;
//    //s.levelOrder(bs);
//    return 0;
//}